using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.Serialization;
using UBlockly.Compotent;
using UBlockly.Graphic;
using UnityEngine;
using UnityEngine.UI;
using UnityEditor;
using Object = UnityEngine.Object;

namespace UBlockly.Editor.Tools
{
    public class BlockGraphicEditor : EditorWindow
    {
        private BlockGraphicAsset graphicAsset;
        [MenuItem("BlockTool/Graphic/外观编辑", false, 42)]
        private static void Open()
        {
            BlockGraphicEditor window = GetWindow<BlockGraphicEditor>(true, "BlockGraphic Editor", true);
            window.maxSize = new Vector2(800f, 600f);
            window.minSize = new Vector2(800,600);
        }
        
        private void OnEnable()
        {
            graphicAsset = new BlockGraphicAsset();
        }

        private void OnGUI()
        {
            EditorGUILayout.BeginHorizontal(GUILayout.Width(position.width), GUILayout.Height(position.height));
        }

        private void DrawSizeSetting()
        {
            
        }

        private void DrawColorSetting()
        {
            
        }

        private void DrawSpriteSetting()
        {
        }

        private void DrawParamGetterSetting()
        {
            
        }
        private void DrawParamPanelSetting()
        {}
    }

//    [CustomEditor(typeof(BlockGraphicAsset))]
//    public class BlockGraphicAssetInspector : UnityEditor.Editor
//    {
//        
//        class SpriteItemData
//        {
//            public string key;
//            public string desc;
//            public Sprite sprite;
//        }
//
//        class SizeItemData
//        {
//            public string key;
//            public string desc;
//            public float value;
//        }
//
//        class ColorItemData
//        {
//            public string key;
//            public string desc;
//            public Color color;
//        }
//
//        class GetterItemData
//        {
//            public string key;
//            public string desc;
//            public IParamGetterCompotent getter;
//        }
//
//        class SetterItemData
//        {
//            public string key;
//            public string desc;
//            public IParamSetterPanel panel;
//        }
//        
//        private BlockGraphicAsset asset;
//        private List<SpriteItemData> spriteItems = new List<SpriteItemData>();
//        private List<SizeItemData> sizeItems = new List<SizeItemData>();
//        private List<ColorItemData> colorItems = new List<ColorItemData>();
//        private List<GetterItemData> getterItems = new List<GetterItemData>();
//        private List<SetterItemData> setterItems = new List<SetterItemData>();
//        private bool displaySizePanel;
//        private bool displaySpritePanel;
//        private bool displayColorPanel;
//        private bool displayGetterPanel;
//        private bool diisplaySetterPanel;
//
//        private Image sprite;
//        public override void OnInspectorGUI()
//        {
//            GUILayout.Toggle(true, "设置尺寸");
//
//            if (GUILayout.Button("展开尺寸设置面板"))
//                displaySizePanel = !displaySizePanel;
//            if (displaySizePanel)
//            {
//                DisplaySizeSetting();
//            }
//            if (GUILayout.Button("展开颜色设置面板"))
//                displayColorPanel = !displayColorPanel;
//            if (displayColorPanel)
//            {
//                DisplayColorSetting();
//            }
//            if (GUILayout.Button("展开精灵面板"))
//                displaySpritePanel = !displaySpritePanel;
//            if (displaySpritePanel)
//            {
//                DisplaySpriteSetting();
//            }
//            if (GUILayout.Button("展开Getter组件设置面板"))
//                displayGetterPanel = !displayGetterPanel;
//            if (displayGetterPanel)
//            {
//                DisplayGetterSetting();
//            }
//            if (GUILayout.Button("展开SetterPanel设置面板"))
//                diisplaySetterPanel = !diisplaySetterPanel;
//            if (diisplaySetterPanel)
//            {
//                DisplaySetterSetting();
//            }
//        }
//
//        private void DisplaySpriteSetting()
//        {
//            asset.testSp = (Sprite) EditorGUILayout.ObjectField("测试sprite   ", asset.testSp, typeof(Sprite), false,
//                GUILayout.Width(180),GUILayout.Height(80));
//            foreach (var item in spriteItems)
//            {
//                //GUILayout.BeginHorizontal();
//                //EditorGUILayout.ObjectField()
//                item.sprite = (Sprite) EditorGUILayout.ObjectField($"{item.key}+{item.desc}:    ", item.sprite, typeof(Sprite), false,
//                    GUILayout.Width(180),GUILayout.Height(80));
//                //GUILayout.EndHorizontal();
//            }
//        }
//        private void DisplaySizeSetting()
//        {
//            foreach (var item in sizeItems)
//            {
//                GUILayout.BeginHorizontal();
//                //EditorGUILayout.ObjectField()
//                item.value = EditorGUILayout.FloatField($"{item.key}:    ", item.value);
//                GUILayout.EndHorizontal();
//            }
//        }
//        private void DisplayColorSetting()
//        {
//            foreach (var item in colorItems)
//            {
//                GUILayout.BeginHorizontal();
//                //EditorGUILayout.ObjectField()
//                item.color = EditorGUILayout.ColorField($"{item.key}:    ", item.color,
//                    GUILayout.Width(280),GUILayout.Height(20));
//                GUILayout.EndHorizontal();
//            }
//        }
//        private void DisplayGetterSetting()
//        {
//            foreach (var item in getterItems)
//            {
//                GUILayout.BeginHorizontal();
//                //EditorGUILayout.ObjectField()
//                item.getter = (IParamGetterCompotent) EditorGUILayout.ObjectField($"{item.key}:    ", item.getter, typeof(IParamGetterCompotent), false,
//                    GUILayout.Width(180),GUILayout.Height(40));
//                GUILayout.EndHorizontal();
//            }
//        }
//        private void DisplaySetterSetting()
//        {
//            foreach (var item in setterItems)
//            {
//                GUILayout.BeginHorizontal();
//                //EditorGUILayout.ObjectField()
//                item.panel = (IParamSetterPanel) EditorGUILayout.ObjectField($"{item.key}:    ", item.panel, typeof(IParamSetterPanel), false,
//                    GUILayout.Width(180),GUILayout.Height(40));
//                GUILayout.EndHorizontal();
//            }
//        }
//
//        private void OnEnable()
//        {
//            Debug.LogError("123");
//            asset = target as BlockGraphicAsset;
//            spriteItems.Clear();
//            sizeItems.Clear();
//            colorItems.Clear();
//            getterItems.Clear();
//            setterItems.Clear();
//            
//            asset.ForEachSprite((key,sprite) =>
//            {
//                spriteItems.Add(new SpriteItemData(){key = key,desc = "测试",sprite = sprite});
//            });
//            if (spriteItems.Count == 0)
//            {
//                var sprites = Enum.GetNames(typeof(SpriteDefine));
//                foreach (var sp in sprites)
//                {
//                    spriteItems.Add(new SpriteItemData(){key = sp,desc = "ff",sprite = null});
//                }
//            }
//            asset.ForEachColor((key, cc) =>
//            {
//                colorItems.Add(new ColorItemData(){key = key,desc = "",color = cc});
//            });
//            asset.ForEachSize((key, value) =>
//            {
//                sizeItems.Add(new SizeItemData(){key = key,desc = "",value = value});
//            });
//            asset.ForEachGetter((key, gg) =>
//            {
//                getterItems.Add(new GetterItemData(){key = key,desc = "",getter = gg});
//            });
//            asset.ForEachSetter((key, ss) =>
//            {
//                setterItems.Add(new SetterItemData(){key = key,desc= "", panel = ss});
//            });
//        }
//
//        private void OnDisable()
//        {
//            Debug.LogError("456");
//            foreach (var sp in spriteItems)
//            {
//                asset.SetSprite(sp.key,sp.sprite);
//            }
//            
//        }
//    }
}

